package com.yiwei.controller.utils;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class UrlUtils {
	public static void main(String[] args) throws Exception {
		String u = "https://yw-images-output.yiweiimage.com/prod/tijianA/48ae1bdc87ba4bd4b4e8.jpg";

		boolean isOk = checkUrl(u);

		System.out.println(isOk);

	}

	public static boolean checkUrl(String u) {
		boolean isOk = false;
		try {
			URL url = new URL(u);
			HttpURLConnection huc = (HttpURLConnection) url.openConnection();
			int responseCode = huc.getResponseCode();

			if (responseCode != 404) {
				isOk = true;
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			return isOk;
		}
	}
}
